package com.gitee.huanminabc.utils_tools.class_extend.javassist;

import javassist.ClassPool;

public interface ClassAspect {
    /**
     * 前置通知
     *
     * @param targetClass 目标类
     * @param methodName  目标方法
     * @param args        目标参数
     */
    default void before(Class<?> targetClass, String methodName, Object[] args) {
    }

    /**
     * 后置通知,异常不会执行
     *
     * @param targetClass
     * @param methodName
     * @param args
     */
    default void after(Class<?> targetClass, String methodName, Object[] args, Object result) {
    }

    default void after(Class<?> targetClass, String methodName, Object[] args, boolean result) {
        after(targetClass, methodName, args, (Object) result);
    }

    default void after(Class<?> targetClass, String methodName, Object[] args, int result) {
        after(targetClass, methodName, args, (Object) result);
    }

    default void after(Class<?> targetClass, String methodName, Object[] args, double result) {
        after(targetClass, methodName, args, (Object) result);
    }

    default void after(Class<?> targetClass, String methodName, Object[] args, long result) {
        after(targetClass, methodName, args, (Object) result);
    }

    default void after(Class<?> targetClass, String methodName, Object[] args, float result) {
        after(targetClass, methodName, args, (Object) result);
    }

    default void after(Class<?> targetClass, String methodName, Object[] args, char result) {
        after(targetClass, methodName, args, (Object) result);
    }

    default void after(Class<?> targetClass, String methodName, Object[] args, byte result) {
        after(targetClass, methodName, args, (Object) result);
    }

    default void after(Class<?> targetClass, String methodName, Object[] args, short result) {
        after(targetClass, methodName, args, (Object) result);
    }


    /**
     * 返回通知,异常会执行
     *
     * @param targetClass
     * @param methodName
     * @param args
     */
    default void afterReturning(Class<?> targetClass, String methodName, Object[] args, Object result) {
    }

    default void afterReturning(Class<?> targetClass, String methodName, Object[] args, boolean result) {
        afterReturning(targetClass, methodName, args, (Object) result);
    }

    default void afterReturning(Class<?> targetClass, String methodName, Object[] args, int result) {
        afterReturning(targetClass, methodName, args, (Object) result);
    }

    default void afterReturning(Class<?> targetClass, String methodName, Object[] args, double result) {
        afterReturning(targetClass, methodName, args, (Object) result);
    }

    default void afterReturning(Class<?> targetClass, String methodName, Object[] args, long result) {
        afterReturning(targetClass, methodName, args, (Object) result);
    }

    default void afterReturning(Class<?> targetClass, String methodName, Object[] args, float result) {
        afterReturning(targetClass, methodName, args, (Object) result);
    }

    default void afterReturning(Class<?> targetClass, String methodName, Object[] args, char result) {
        afterReturning(targetClass, methodName, args, (Object) result);
    }

    default void afterReturning(Class<?> targetClass, String methodName, Object[] args, byte result) {
        afterReturning(targetClass, methodName, args, (Object) result);
    }

    default void afterReturning(Class<?> targetClass, String methodName, Object[] args, short result) {
        afterReturning(targetClass, methodName, args, (Object) result);
    }


    /**
     * 异常通知
     *
     * @param targetClass
     * @param methodName
     * @param args
     * @param e           异常
     */
    default void afterThrowing(Class<?> targetClass, String methodName, Object[] args, Throwable e) {
    }

    //修改方法
    default String modifyMethodBody(ClassPool cPool) {
        return null;
    }

}
